/*! \file */
/// \addtogroup MegaMan
/// \{
#ifndef __MegaMan_h__
#define __MegaMan_h__

//////////////////////////////////////////////////////////////////////////////////////////////////////
// Macro definitions
// Bit shift magic
#define getRightN(pixelByte) (pixelByte & 0x0F)		///< Get the right 4bit nibble from  pixelByte
#define getLeftN(pixelByte) (pixelByte >> 4 & 0x0F)	///< Get the left 4bit nibble from pixelByte

#define setRightN(buffer,pixelByte) buffer = (buffer & 0xF0 | (pixelByte & 0x0F))		///< Set right 4bit nibble of buffer with content of pixelByte
#define setLeftN(buffer,pixelByte) buffer = (buffer & 0x0F| (pixelByte << 4 & 0xF0))	///< Set left 4bit nibble of buffer with content of pixelByte
  
#define joinNibbles(pixelByte,lsbPixel,msbPixel) pixelByte = (lsbPixel & 0x0F| msbPixel << 4 & 0xF0)	///< Join two 4bit nibbles (lsbPixel and msbPixel) into a single byte (pixelByte)

/* a=register, b=bit number to act upon */
#define BIT_SET(a,b) ((a) |= (1<<(b)))		///< Set bit number b of register/byte/variable a
#define BIT_CLEAR(a,b) ((a) &= ~(1<<(b)))	///< Clear bit number b of register/byte/variable a
#define BIT_FLIP(a,b) ((a) ^= (1<<(b)))		///< Flip bit number b of register/byte/variable a
#define BIT_CHECK(a,b) ((a) & (1<<(b)))		///< Check if bit number b of register/byte/variable is set

/* x=target variable, y=mask */
#define BITMASK_SET(x,y) ((x) |= (y))		///< Set bitmask y on variable x
#define BITMASK_CLEAR(x,y) ((x) &= (~(y)))	///< Clear bitmask y on variable x
#define BITMASK_FLIP(x,y) ((x) ^= (y))		///< Flip bitmask y onto variable x
#define BITMASK_CHECK(x,y) ((x) & (y))		///< Check for bitmask y on variable x


// Externally available functions
void imageFromFlash(unsigned char *);			///< Copies an image from flash to Peggy
void updatePeggyDisplay(char *);		///< Updates Peggy - by sending custom made headers. All processing takes place on Peggy
void alterBuffer(char *, unsigned char *);		///< Change the frameBuffer - typically to create graphical effects
void sendBuffer(uint8_t *);			///< Transmit the frameBuffer to Peggy
void putPixel(uint8_t, uint8_t, uint8_t);	///< Display single pixel on Peggy through slow method of transferring entire frameBuffer

extern boolean abortFlag;			///< Flag to abort execution if external event demands it

#endif /* __MegaMan_h__ */

/// \}
